package kr.pe.dothome.yyar.myphone.domain;

import java.util.Date;

public class MissedMessage {
	public static final int CALL_LOG = 0;
	public static final int SMS = 1;
	public static final int MMS = 2;
	
	private String requestId;
	private int messageType;
	private String name;
	private String address;
	private Long messageDate;
	private String content;
	
	// TODO not implemented
	private byte[] detail;
	
	private MissedMessage() {}
	
	private MissedMessage(String rid, int messageType, String name, String address, Long messageDate, String content, byte[] detail) {
		this.requestId = rid;
		this.messageType = messageType;
		this.name = name;
		this.address = address;
		this.messageDate = messageDate;
		this.content = content;
		this.detail = detail;
	}
	
	public static MissedMessage callLog (String rid, String name, String address, Long messageDate) {
		return new MissedMessage(rid, CALL_LOG, name, address, messageDate, null, null);
	}
	
	public static MissedMessage sms (String rid, String name, String address, Long messageDate, String content) {
		return new MissedMessage(rid, SMS, name, address, messageDate, content, null);
	}
	
	public static MissedMessage mms (String rid, String name, String address, Long messageDate, String content, byte[] detail) {
		return new MissedMessage(rid, MMS, name, address, messageDate, content, detail);
	}
	
	@Override
	public String toString() {
		String typeString = messageType == 0 ? "CALL_LOG" :
							messageType == 1 ? "SMS" : "MMS";
		
		String dateString = new Date(messageDate * 1000) .toString();
		String hasDetail = detail == null || detail.length == 0 ? "NO" : "YES";
		
		return "RID : " + requestId + "\n" 
			+ "TYPE : " + typeString + "\n"
			+ "NAME : " + name + "\n"
			+ "ADDRESS : " + address + "\n"
			+ "DATE : " + dateString + "\n"
			+ "Content : " + content + "\n"
			+ "has Detail Content : " + hasDetail + "\n";
	}

	public String getPostQuery() {
		if(name == null)
			name = "";
		if(content == null)
			content = "";
		
		return "rid="+requestId
				+"&mtype="+messageType
				+"&name="+name
				+"&address="+address
				+"&mdate="+String.valueOf(messageDate)
				+"&content="+content;
	}
}
